<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>全球疫情实时更新</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo"><strong>全球疫情实时更新</strong></div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item"><a href="/index">国内</a></li>
                <li class="layui-nav-item layui-this"><a href="/color/index">国内疫情分布图</a></li>
                <li class="layui-nav-item"><a href="/foreign">国外</a></li>
                <li class="layui-nav-item"><a href="/color">全球对比图</a></li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <div style="padding: 15px;">
            <div id="main" style="width: 900px; height:800px;"></div>
        </div>
    </div>
</div>
<script src="../layui/layui.js"></script>
<script>
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;
    });

    var myChart = echarts.init(document.getElementById('main'));
    myChart.setOption({
        radius: '60%',
        series: [{
            name: '感染人数',
            type: 'pie',
            data: []
        }]
    });

    //异步加载数据
    $.get('/color/china').done(function (data) {
        var servicedata=[];
        for(var i = 0;i < data.name.length;i++) {
            var obj = new Object();
            obj.name = data.name[i];
            obj.value = data.value[i];
            servicedata[i] = obj;
        }
        // 填入数据
        myChart.setOption({
            legend: {
                orient : 'vertical',
                x: '90%',
                data:data.name,
            },
            radius: '40%',
            series: [{
                // 根据名字对应到相应的系列
                name: '感染人数',
                data: servicedata
            }]
        });
    });

</script>
</body>
</html>